package com.sx.zongzhi.adapter;


import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.sx.zongzhi.R;
import com.sx.zongzhi.bean.PopulationDetailBean;
import com.sx.zongzhi.net.ServiceFactory;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.io.File;
import java.util.List;

/**
 * Created by XZY on 2017/11/23.
 * 人口关系
 */

public class RelationAdapter extends CommonAdapter<PopulationDetailBean.InfoBean.RowsBean> {

    private Context context;

    public RelationAdapter(Context context, int layoutId, List<PopulationDetailBean.InfoBean.RowsBean> datas) {
        super(context, layoutId, datas);
        this.context=context;
    }

    @Override
    protected void convert(ViewHolder viewHolder, PopulationDetailBean.InfoBean.RowsBean item, int position) {
        viewHolder.setText(R.id.tv_Sex,item.getGender()!=null?item.getGender().getDisplayName():"未知");
        viewHolder.setText(R.id.tv_Age,item.getAge()+"岁");
        viewHolder.setText(R.id.tv_Relation,item.getRelationShipWithHead()!=null ? item.getRelationShipWithHead().getDisplayName():"未知");
        viewHolder.setText(R.id.tv_Name, item.getName()+"("+item.getIdCardNo()+")");
        ImageView imageView=viewHolder.getView(R.id.imv_Head);
        RequestOptions options = new RequestOptions()
                .centerCrop()
                .placeholder(R.mipmap.head_default)
                .diskCacheStrategy(DiskCacheStrategy.RESOURCE);
        Glide.with(context)
                .load(ServiceFactory.NEW_API_BASE_URL+ File.separator+item.getImgUrl())
                .apply(options)
                .into(imageView);
    }

}
